package view;

import javax.faces.component.UIComponent;
import javax.faces.event.ActionEvent;

import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.adf.view.rich.component.rich.RichDialog;
import oracle.adf.view.rich.component.rich.RichPopup;
import oracle.adf.view.rich.component.rich.nav.RichLink;

import oracle.jbo.domain.Number;

import org.apache.myfaces.trinidad.component.UIXIterator;

public class OperationsIteratorMB {
    private UIXIterator iteratorZaposlenika;
    private RichPopup popUp;


    public OperationsIteratorMB() {
    }

    public String prosli() {
        // Add event code here...
        getIteratorZaposlenika().setFirst(getIteratorZaposlenika().getFirst() - 20);
        return null;
    }

    public String iduci() {
        // Add event code here...
        getIteratorZaposlenika().setFirst(getIteratorZaposlenika().getFirst() + 20);
        return null;
    }

    public void setIteratorZaposlenika(UIXIterator iteratorZaposlenika) {
        this.iteratorZaposlenika = iteratorZaposlenika;
    }

    public UIXIterator getIteratorZaposlenika() {
        return iteratorZaposlenika;
    }

    public String zadnji() {
        // Add event code here...
        getIteratorZaposlenika().setFirst(getIteratorZaposlenika().getRowCount() - 20);
        return null;
    }

    public String prvi() {
        // Add event code here...
        getIteratorZaposlenika().setFirst(0);
        return null;
    }

    public boolean isPrvaDisabled() {
        return getIteratorZaposlenika().getFirst() == 0;
    }

    public int getTrenutnaStranica() {
        return getIteratorZaposlenika().getFirst() / 20 + 1;
    }

    public void otvoriPopUp(ActionEvent actionEvent) {
        RichLink link = (RichLink) actionEvent.getSource();
        Integer k01ctr = (Integer) link.getAttributes().get("trenutniZaposlenik");
        System.out.println(k01ctr);

        DCBindingContainer dcBc = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();
        DCIteratorBinding dcIb = dcBc.findIteratorBinding("Fk001View1Iterator");
        dcIb.setCurrentRowWithKeyValue(k01ctr.toString());

        RichPopup.PopupHints hints = new RichPopup.PopupHints();
        
        UIComponent source = (UIComponent) actionEvent.getSource();           
         //  RichPopup.PopupHints hints = new RichPopup.PopupHints();
           hints.add(RichPopup.PopupHints.HintTypes.HINT_ALIGN_ID, source)
                .add(RichPopup.PopupHints.HintTypes.HINT_LAUNCH_ID, source)
                .add(RichPopup.PopupHints.HintTypes.HINT_ALIGN, RichPopup.PopupHints.AlignTypes.ALIGN_AFTER_END);        
        
        getPopUp().show(hints);
    }

    public void setPopUp(RichPopup popUp) {
        this.popUp = popUp;
    }

    public RichPopup getPopUp() {
        return popUp;
    }
}
